<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/stylesite.css" medial="all" />
<link rel="stylesheet" type="text/css" href="../css/styleleft.css" medial="all" />
<link rel="stylesheet" type="text/css" href="../css/mystyle.css" />
<script type="text/javascript" src="../js/jquery-1.8.2.min.js"></script>
<style>
    a{color: blue;}
    a:hover{color: #f80c0c;}
</style>
	<script type="text/javascript" src="../js/jquery-1.8.2.min.js" ></script>
	<script src="../js/image.js" type="text/javascript"></script>
        <script src="../js/jsearch.js" type="text/javascript"></script>        
    <script type="text/javascript">
	$(document).ready(function(){
		$('#files').change(function (evt) {
			var f = evt.target.files[0];
			var reader = new FileReader();
	
			if (!f.type.match('image.*')) {
				alert("The selected file does not appear to be an image.");
				return;
			}
	
			reader.onload = function (e) {
				//$('#preview').attr('src', e.target.result);
	
				$('#preview').css("background-image","url("+e.target.result+")");
			};
			reader.readAsDataURL(f);
		});
	});
         var xmlHttp;
		function checkProductName(str)
		{
                     var xmlHttp;
                if (window.XMLHttpRequest)
                {
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlHttp=new XMLHttpRequest();

                }
                else
                {
                    // code for IE6, IE5
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
		        xmlHttp.onreadystatechange=function()
                {
                    if (xmlHttp.readyState==4)
					{
                        if (xmlHttp.status == 200) 
						{
						// 	window.alert("test thoi");
				//            document.myform.anbum.value=xmlHttp.responseText;
                     		document.getElementById('idcheck').innerHTML=xmlHttp.responseText;
                       }
                        else {
                            // Có lỗi! Thông báo ngay!
                            alert('Lỗi!!!');
                        }
                    }
                    else {
                        // loading…
                    }
                }
                var url='c_checkProductName.php';
				var test;
				//test=document.getElementById('idselect').value;
				//test=document.myform.select1.value;
				url=url+"?productName="+str;
				
                xmlHttp.open("GET",url,true);
                xmlHttp.send(null);
		}
	</script>
   
<title>QUẢN LÝ DANH MỤC</title>
</head>

<body class="pagebody">
	<div id="wrapwebsite" >
            <?php 
            include('../element/header_adm.php');
                                ?>
            <div class="imagestop"></div>
            <div class="wrapmaincontent">

                <div id="maincontent">
                    <?php
                    if(!isset($_SESSION['user'])|| $_SESSION['user'][4]!='admin')
                        {      
                            echo '<p>Bạn không được quyền xem trang này</p>';
                             header ('location:/cfshop/home.php');
                        }
                        else
                        {
                    ?>
                    <p>THÊM MỚI SẢN PHẨM</p>
                    <?php
                                    include_once '../adm_Category/category_model.php';
                                    $arr_cate=array();
                                    $arr_cate=  getAllCategory();                       
                    ?>
                    <form action="c_addNewProduct.php" method="post" enctype='multipart/form-data'>
                    <table width="600" border="0" cellspacing="5" cellpadding="3" id="table">
                      <tr>
                        <td width="200">&nbsp;Product Name</td>
                        <td>&nbsp;<input name="txtProductName" type="text" size="65" onBlur="checkProductName(this.value)" />
                            <div id="idcheck"></div>
                        </td>
                      </tr>
                      <tr>
                        <td>&nbsp;Description</td>
                        <td>&nbsp;<textarea name="txtDescription" cols="50" rows="10"></textarea></td>
                      </tr>
                      <tr>
                        <td>&nbsp;Price</td>
                        <td>&nbsp;<input name="txtPrice" type="text" size="65" /></td>
                      </tr>
                      <tr>
                        <td>&nbsp;Size</td>
                        <td>&nbsp;<input name="txtSize" type="text" size="65" /></td>
                      </tr>
                      <tr>
                        <td>&nbsp;Category</td>
                        <td>&nbsp;<select name="selectCate">
                        <?php
                          foreach ($arr_cate as $category) {
                                echo '<option value="'.$category['ID'].'">'.$category['CategoryName'].'</option>';
                              
                                    }
						?>
                                </select>
                        </td>
                      </tr>
                      <tr>
                        <td>&nbsp;Image of product</td>
                        <td>&nbsp;
                            <div id="upload_panel">
                            <input type='file' name='img' id="files"/>
                            <div id="preview"></div>
                            </div>
                        </td>
                      </tr>
                       <tr>
                        <td colspan="2" align="center">&nbsp;<input name="submit" type="submit" value="Add New Product"  /><input name="reset" type="reset" value="Reset" />
                        </td>
                        
                      </tr>
                    </table>

                 </form> 
                </div>
                <?php
                        }
                        ?>
                
           </div>         
		
</div>
</body>
</html>
